package xyz.kongbai121.drawingbed.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
@ConfigurationProperties(prefix = "drawing-bed.swagger")
public class SwaggerConfig {

    @Getter @Setter
    private boolean swaggerOpen;

    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("drawing-bed")
                .enable(swaggerOpen)//是否启用swagger
                .select()
                //配置要扫描接口的方式
                //basePackage指定扫描的包
                .apis(RequestHandlerSelectors.basePackage("xyz.kongbai121.drawingbed.controller"))
//                .paths(PathSelectors.ant("/kongbai/**"))//过滤什么路径
                .build();
    }

    private ApiInfo apiInfo(){

        //作者信息
        Contact contact = new Contact("空白", "https://kongbai121.xyz", "475274642@qq.com");

        return new ApiInfo(
                "空白的drawing-bedAPI文档",
                "只要学不死就往死里学",
                "v1.0",
                "https://kongbai121.xyz",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }

}